<template>
  <a-spin :spinning="loading">
    <div>
      <a-form-model
        class="fromModels"
        ref="selfUseRateNumberModel"
        layout="vertical"
        :labelCol="{ span: 12 }"
        :wrapperCol="{ span: 12 }"
      >
        <div class="centes">
          <div class="centes_confis">
            <a-form-model-item label="自用费率笔数费分润">
              <a-radio-group :disabled="disableds" v-model="status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="税费费率">
              <a-input :disabled="disableds" v-model="config.tax_rate">
                <div slot="addonAfter">万</div>
              </a-input>
            </a-form-model-item>
          </div>
        </div>

        <div class="confish">
          <div class="confish_items">
            <a-form-model-item label="代还自用费率级差分润">
              <a-radio-group :disabled="disableds" v-model="config.repayment_rate_status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="代还自用最低费率">
              <a-input :disabled="disableds" v-model="config.repayment_rate">
                <div slot="addonAfter">元</div>
              </a-input>
            </a-form-model-item>
            <a-form-model-item label="代还自用笔数费级差分润">
              <a-radio-group :disabled="disableds" v-model="config.repayment_fee_status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="代还自用最低笔数费">
              <a-input :disabled="disableds" v-model="config.repayment_fee">
                <div slot="addonAfter">元</div>
              </a-input>
            </a-form-model-item>
          </div>

          <div class="confish_items">
            <a-form-model-item label="快捷自用费率级差分润">
              <a-radio-group :disabled="disableds" v-model="config.collection_rate_status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="代还自用最低笔数费">
              <a-input :disabled="disableds" v-model="config.collection_rate">
                <div slot="addonAfter">元</div>
              </a-input>
            </a-form-model-item>
            <a-form-model-item label="快捷自用笔数费级差分润">
              <a-radio-group :disabled="disableds" v-model="config.collection_fee_status">
                <a-radio :value="1"> 开 </a-radio>
                <a-radio :value="0"> 关 </a-radio>
              </a-radio-group>
            </a-form-model-item>
            <a-form-model-item label="快捷自用最低笔数费">
              <a-input :disabled="disableds" v-model="config.collection_fee">
                <div slot="addonAfter">元</div>
              </a-input>
            </a-form-model-item>
          </div>
        </div>

        <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
          <a-button type="primary" @click="whites">提交</a-button>
          <a-button type="primary" @click="getPrivacyAgreementInfo">重置</a-button>
          <a-button type="primary" @click="disableds = !disableds">{{ disableds ? '启用编辑' : '关闭编辑' }}</a-button>
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-spin>
</template>

<script>
import { getRebateApi, setRebateApi } from '@/api/return.js'
export default {
  name: 'selfUseRateNumber',

  data() {
    return {
      loading: false,
      disableds: true,
      config: {
        collection_fee: '0',
        collection_fee_status: 0,
        collection_rate: '0',
        collection_rate_status: 0,
        repayment_fee: '0',
        repayment_fee_status: 0,
        repayment_rate: '0',
        repayment_rate_status: 0,
        tax_rate: '0'
      },
      status: 1
    }
  },
  created() {
    this.getPrivacyAgreementInfo()
  },
  methods: {
    getPrivacyAgreementInfo() {
      this.loading = true
      getRebateApi({
        type: 'self_rate_fee_differ_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID
      })
        .then(res => {
          this.config = res.data.config
          this.status = res.data.status
        })
        .finally(() => {
          this.loading = false
        })
    },
    whites() {
      this.setDatas()
    },
    setDatas() {
      setRebateApi({
        type: 'self_rate_fee_differ_rebate',
        brand_id: process.env.VUE_APP_BRAND_ID,
        status: this.status,
        data: this.config
      }).then(res => {
        this.getPrivacyAgreementInfo()
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.centes {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}
.centes_confis {
  width: 50%;
}
.confish {
  display: flex;
  align-items: self-start;
  justify-content: space-between;
}
.confish_items {
  width: 48%;
}
</style>
